package cate.game.activity.specall;


import cate.common.table.d.GDFunc;
import cate.common.table.pay.PayItemRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.base.core.RoleActivitySingle;
import cate.game.activity.loopfund.LoopMonthFundActivity;
import cate.game.pay.PayCallback;
import cate.game.pay.PayHandler;
import cate.game.role.Role;
import cp.solution.business.pay.PayRecordEntity;
import cp.solution.business.pay.dto.PayDeliverResult;

@PayHandler(funcIds = {GDFunc.SPE_CALL,GDFunc.SPE_CALL_WAR_ORDER})
public class SpeCallPayCallback extends PayCallback {
    @Override
    public void onSuccess(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {
        PayItemRow pir = game.table.pay.item.get(record.itemTid);
        if (pir == null) {
            return;
        }
        SpeCallActivity single = role.getActivity().getEnableActivitySingle(GDFunc.SPE_CALL);
        if (single != null) {
            if (pir.funcId == GDFunc.SPE_CALL) {
                single.starGift.onPaySuccess(pir);
            }else if (pir.funcId == GDFunc.SPE_CALL_WAR_ORDER) {
                single.warOrder.onPaySuccess(pir);
            }
        }
    }

    @Override
    public void onFail(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {

    }

    @Override
    public GameResult<Void> allowPay(Role role, PayItemRow pir) {
        SpeCallActivity act = role.getActivity().getEnableActivitySingle(GDFunc.SPE_CALL);
        if (act != null) {
            if (pir.funcId == GDFunc.SPE_CALL) {
                return act.starGiftAllowPay(pir);
            }else if (pir.funcId == GDFunc.SPE_CALL_WAR_ORDER) {
                return act.warOrderAllowPay(pir);
            }
        }
        return new GameResult<Void>().fail();
    }
}
